from fastapi import APIRouter
from fastapi.responses import JSONResponse
import os
import glob

# Define the directory where templates are stored
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "..", "templates")

router = APIRouter()

@router.get("/templates",
         summary="List available Excel template names",
         response_description="List of .xlsx template filenames")
async def list_templates():
    """
    Retrieves a list of available .xlsx template files located in the server's template directory.
    """
    template_files = glob.glob(os.path.join(TEMPLATE_DIR, "*.xlsx"))
    template_names = [os.path.basename(f) for f in template_files]
    return JSONResponse(content={"templates": template_names}) 